package ws.very.common.web.com

import scala.math.Ordered
import ws.very.util.lang.WeekTypeCookies
object AppVersion {
  private val pattern = """^(\d+)\.(\d+)\.(\d+)$""".r
  def apply(versionNo: S): AppVersion = {
    val pattern(n1, n2, n3) = versionNo
    AppVersion(n1.toInt, n2.toInt, n3.toInt)
  }
  val default = AppVersion(1, 0, 0)
}
case class AppVersion(big: I, basic: I, small: I) extends Ordered[AppVersion] {
  override def compare(that: AppVersion) = {
    val (n1, n2, n3) = (big - that.big, basic - that.basic, small - that.small)
    if (n1 != 0) n1
    else if (n2 != 0) n2
    else n3
  }
  override def toString() = s"$big.$basic.$small"

}

object Client {
  val default = Client("未知", AppVersion.default)
}
case class Client(name: S, version: AppVersion) {

  override def toString = s"$name-$version"
}